// 轮播图,展示最新的五本书,如果文档库的书的总数小于5,就展示对应数量的书

export async function fetchCarouselBooks(proxy) {
    try {
        const response = await proxy.$http.get('/api/book/all');

        // 检查响应的实际结构
        if (response.data && response.data.data && response.data.data.book) {
            const sortedBooks = response.data.data.book.sort((a, b) => new Date(b.upload_time) - new Date(a.upload_time));
            return sortedBooks.slice(0, 5);
        } 
        else
            console.error('轮播图，响应结构不符合预期:', response);

    } catch (error) {
        console.error('Error fetching carousel books:', error);
        throw error;
    }
}

